package com.codemes.happylist.modules.webview;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import lombok.extern.slf4j.Slf4j;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * @author nscoffee
 */
@Slf4j
public class WebBrowseController implements Initializable {

    @FXML
    private WebView resultWebView;

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        log.info("初始化>>>>>>>>>>>>>>");
        final WebEngine webEngine = resultWebView.getEngine();

        webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>(){

            @Override
            public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
                log.info("{}",newValue);
                if(newValue == Worker.State.SUCCEEDED){
                    log.info("加载成功>>>>>>>>>");
                }
            }
        });

        webEngine.load("http://localhost");
    }
}
